package com.bluefoxyu.controller;


import com.bluefoxyu.domain.dto.EnrollmentPageQueryDTO;
import com.bluefoxyu.domain.entity.Enrollment;
import com.bluefoxyu.domain.result.PageResult;
import com.bluefoxyu.domain.result.Result;
import com.bluefoxyu.domain.vo.EnrollmentVO;
import com.bluefoxyu.domain.vo.StudentTotalGradeVO;
import com.bluefoxyu.service.IEnrollmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 选课成绩表 前端控制器
 * </p>
 *
 * @author bluefoxyu
 * @since 2024-06-16
 */
@RestController
@RequestMapping("/enrollment")
@RequiredArgsConstructor
@Tag(name ="管理页面选课成绩表接口")
public class EnrollmentController {

    private final IEnrollmentService enrollmentService;

    //当学生选修了某门课程，课程成绩由管理员录入；
    @Operation(summary = "学生选修了某门课程，课程成绩由管理员录入")
    @PutMapping("/addEnrollment")
    public Result<String> addEnrollment(@RequestBody Enrollment enrollment) {
        enrollmentService.updateById(enrollment);
        return Result.success("学生课程成绩录入成功");
    }

    @Operation(summary = "查询选课成绩表全部信息")
    @GetMapping("/getEnrollment")
    public Result<PageResult> getEnrollment(@ParameterObject EnrollmentPageQueryDTO enrollmentPageQueryDTO) {
        return Result.success(enrollmentService.pageQuery(enrollmentPageQueryDTO));
    }

    //统计每门课程的平均成绩、最高分、最低分
    @Operation(summary = "统计每门课程的平均成绩、最高分、最低分")
    @GetMapping("/getEnrollmentStatistics")
    public Result<EnrollmentVO> getEnrollmentStatistics() {
        return Result.success(enrollmentService.getEnrollmentStatistics());
    }

    @Operation(summary = "统计每个学生选修课程的总学分")
    @GetMapping("/getCreditByStudent")
    public Result<List<StudentTotalGradeVO>> getCreditByStudent() {
        return Result.success(enrollmentService.getCreditByStudent());
    }

}
